<template>
  <div >
    <div class="pgbanner">
      <img src="/static/images/pgbanner3.jpg" alt="">
    </div>
    <div class="pgtitle">
      <div class="word">
        <div class="cn">新闻资讯</div>
        <div class="en">Company NEWS</div>
      </div>
    </div>
    <div>
      <div class="content" style="margin: 30px auto;">
        <div v-for="(item,key) in list" :key="key" class="list clearfix" @click="goContent(item.id)">
          <img :src="item.img" alt="" class="img" mode="widthFix">
          <div class="text clearfix">
            <div class="name">
              {{item.name}}
            </div>
            <div class="date clearfix">
              <div class="time fl">
                <i class="iconfont icon-shijian"></i> {{item.time}}
              </div>
            </div>
          </div>
        </div>
      </div>
      <div>
        <i-load-more :tip="loadingtip" :loading="loadingtrue"/>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "",
    data() {
      return {
        loadingtip:'',
        loadingtrue:true,
        list: [],
        page: 1,
        total_page: 0
      }
    },
    methods: {
      requestData() {
        const that = this;
        // console.log(that)
        const api = 'https://eztw.com.cn/xcxnews311';
        wx.request({
          url: api, //仅为示例，并非真实的接口地址
          data: {
            page: that.page
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success: function (res) {
            wx.stopPullDownRefresh()
//            const data = res.data
            console.log(res.data.total_page)
            if(res.data.total_page==1)
            {
             console.log(res.data.total_page);
              that.loadingtrue=false
              that.loadingtip='暂无数据'
              console.log('数据加载完了')
            }
            if (that.page > 1) {
              that.list.push(...res.data.result)
            }
            else {
              that.list = res.data.result
            }
            that.total_page = res.data.total_page
          }
        })
      },
      goContent(id) {
        // console.log(aid)
        const url = '../newscontent/main?id=' + id;
        wx.navigateTo({url});
      }
    },
    mounted() {
      this.requestData();
    },
    onReachBottom() {
      if (this.page >=this.total_page) {
        this.loadingtrue=false
        this.loadingtip='暂无数据'
        console.log('数据加载完了')
      }
      else {
        this.page = this.page + 1
        this.requestData();
      }
    },
    onPullDownRefresh() {
      console.log('下拉刷新')
      this.loadingtrue=true
      this.loadingtip='正在加载'
      this.page = 1
      this.requestData()
    },
  }
</script>

<style scoped lang=scss>
  .info{
    width: 90%;
    margin:10px auto;
  }
  .content{
    margin-top:20px;
  .list{
    margin-bottom:20px;
  .img{
    width: 40%;
    border-radius: 10px;
    float:left;
  }
  .text{
    float: right;
    width: 55%;
    margin-left:5%;
    padding-top:5px;
  .name{
    color: #333333;
    display: -webkit-box;
    overflow: hidden;
    text-overflow: ellipsis;
    word-wrap: break-word;
    font-size: 14px;
    white-space: normal !important;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .date{
    font-size:12px;
  .iconfont{
    display: inline-block;
    font-size: 12px;
  }
  .liulan{
    margin-right: 20px;
  .iconfont{
    font-size: 14px;
  }
  }
  }
  }
  }
  .more{
    font-size: 13px;
    text-align: center;
    width:80px;
    height: 30px;
    line-height: 30px;
    color: #fff!important;
    margin: 0 auto;
    border-radius: 10px;

  }
  }
  .loadingshow{
    display: none;
  }
</style>
